package com.zsj.mysql.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsj.mysql.entity.AppProductPrice;
import com.zsj.mysql.mapper.AppProductPriceMapper;
import com.zsj.mysql.service.IAppProductPriceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 商户产品折扣表 服务实现类
 * </p>
 *
 * @author
 * @since
 */
@Slf4j
@Service
public class AppProductPriceServiceImpl extends ServiceImpl<AppProductPriceMapper, AppProductPrice> implements IAppProductPriceService {

    @Autowired
    private AppProductPriceMapper mapper;

    @Override
    public BigDecimal findDiscount(String appId, String carrierCode, String productDenomination, String adCode) {
        AppProductPrice appProductPrice = mapper.getByAppCarrierProductAd(appId, carrierCode, productDenomination,
                adCode);
        if (null == appProductPrice) {
            log.info("adCode:{}未查到配置，使用ALL进行查询", adCode);
            appProductPrice = mapper.getByAppCarrierProductAd(appId, carrierCode, productDenomination, "ALL");
            if (null == appProductPrice) {
                log.info("使用ALL未查到配置");
                return null;
            }
        }
        return appProductPrice.getDiscount();
    }
}
